// main.go
package main

import (
	"fmt"
	"github.com/golang/protobuf/proto"
	"golangStudy/service"
)

func main() {
	user := &service.User{
		Username: "xiaoming1",
		Age:      23,
	}

	//序列化过程
	marshal, err := proto.Marshal(user)

	if err != nil {
		panic(err)
	}

	fmt.Printf("序列化后的值:%v\n", marshal) //序列化后的值:[10 9 120 105 97 111 109 105 110 103 49 128 2 23]
	//反序列化
	newUser := &service.User{}
	err = proto.Unmarshal(marshal, newUser)
	if err != nil {
		panic(err)
	}
	fmt.Printf("反序列化后的值:%v\n", newUser.String()) //反序列化后的值:username:"xiaoming1" age:23

}
